package com.tywj.lib.lifecycle.extension

import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import io.reactivex.disposables.Disposable

/**
 * <pre>
 *     author : June Yang
 *     time   : 2020/5/8
 *     desc   : RxJava扩展
 *     version: 1.0.0
 * </pre>
 */


/**
 * 绑定生命周期
 * @param owner 实现了LifecycleOwner的子类
 * @param untilEvent LifecycleOwner发生该事件后，取消订阅，防止发生泄露，默认是 ON_DESTROY 事件
 */
fun Disposable.attachToLifecycle(owner: LifecycleOwner, utilEvent: Lifecycle.Event = Lifecycle.Event.ON_DESTROY) {
    owner.lifecycle.addObserver(LifecycleDisposable(this, owner, utilEvent))

}